package com.example.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.example.dao.impl.PeopleDaoImpl;
import com.example.dao.impl.UserDaoImpl;
import com.example.dao.impl.VehicleDaoImpl;
import com.example.dao2.PeopleDao;
import com.example.dao2.UserDao;
import com.example.dao2.VehicleDao;
import com.example.entity.People;
import com.example.entity.User;
import com.example.entity.Vehicle;
import com.example.entity.VehicleFaultInfo;
import com.google.gson.Gson;

public class VehicleServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html"); 
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		//获得打印输出流
		PrintWriter pw=response.getWriter();
		
		//从request中获取相应的属性
		System.out.println("enter VehicleServlet");
		Gson gson = new Gson();
		
		String jsonString=request.getParameter("jsonString");
		System.out.println("query vehicle sql is "+jsonString);
		Vehicle v = gson.fromJson(jsonString, Vehicle.class);
		System.out.println("json create vehicle  is"+v.toString());
		VehicleDao vd=new VehicleDaoImpl();
	      
		pw.print(	vd.query(v));	

     }

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
            doGet(request, response);
	}
	//初始化方法
	public void init ()throws ServletException{
		
	}
	//构造方法
	public VehicleServlet(){
		super();
	}
	//销毁方法
	public void destory(){
		super.destroy();
	}
public String beanToJson(People people){
	
	Gson gson = new Gson();  
    System.out.println("----------简单对象之间的转化-------------");  
    // 简单的bean转为json  
    String s1 = gson.toJson(people);  
    // System.out.println("简单Bean转化为Json===" + s1);  
    return s1;

}

}
